package example

import (
	"log"
	"math"
	"os"
	"time"

	"fyne.io/fyne/v2/canvas"
	"github.com/tidwall/pinhole"
)

func gopher(img *canvas.Image) {
	p := pinhole.New()
	f, err := os.Open("example/gopher.obj")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	if err = p.LoadObj(f); err != nil {
		log.Fatal(err)
	}
	// gopher is a little offscreen, scale and center it
	p.Scale(0.22, 0.22, 0.22)
	p.Center()
	opts := *pinhole.DefaultImageOptions
	opts.LineWidth = 0.02 // thin lines
	var n = 60
	var step = math.Pi * 2 / float64(n)
	for a := 0.0; a < math.Pi*2; a += step {
		p.Rotate(0, step, 0)
		img.Image = p.Image(300, 300, &opts)
		img.Refresh()
		time.Sleep(time.Millisecond * 100)
	}

}
